package com.xuzao.developer.controller;

import com.github.pagehelper.PageInfo;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.xuzao.developer.base.model.PlanUpdateLog;
import com.xuzao.developer.base.model.ProjectVersion;
import com.xuzao.developer.dao.ProjectVersionDao;
import com.xuzao.developer.dto.PlanUpdateLogDTO;
import com.xuzao.developer.service.PlanUpdateLogService;
import com.xuzao.developer.tools.entity.Pager;
import com.xuzao.developer.utils.IntegerUtil;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @description 
 * @author xuzao
 * @date 2019-08-22 11:44:48
 **/
@Controller
@RequestMapping("/planUpdateLog/")
public class PlanUpdateLogController extends BaseController{

	@Resource
	private PlanUpdateLogService planUpdateLogService;
	@Resource
	private ProjectVersionDao projectVersionDao;

	@RequestMapping("queryList")
	public String queryList(PlanUpdateLogDTO dto, Pager pager, Model model) {
	 	super.initPager(pager);
		List<ProjectVersion> projectVersionList = projectVersionDao.selectListAll();
		List<Map<String, Object>> projectList = Lists.newArrayList();
		Long projectId = null;
		if (!projectVersionList.isEmpty()) {
			for (ProjectVersion o : projectVersionList) {
				Map<String, Object> map = Maps.newHashMap();
				map.put("id", o.getId());
				map.put("name", o.getName());
				if (dto.getProjectId() != null && IntegerUtil.equalTo(dto.getProjectId(), o.getId())) {
					map.put("selected", "selected");
				} else {
					map.put("selected", "");
					projectId = o.getId();
				}
				projectList.add(map);
			}

			if (dto.getProjectId() == null) {
				dto.setProjectId(projectId);
			}
		}
		PageInfo<PlanUpdateLog> pageInfo = planUpdateLogService.list(dto,pager);
		model.addAttribute("pageInfo",pageInfo);
		model.addAttribute("projectList",projectList);
		model.addAttribute("bo",dto);
		return "/plan_update_log/plan_update_log_list";
	}



}